package com.sx.baseproject.framework.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;

import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.header.MaterialHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
import com.sx.baseproject.R;

public class ThemeRefreshLayout extends SmartRefreshLayout {
    public ThemeRefreshLayout(Context context) {
        super(context);
    }

    public ThemeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(attrs);
    }

    public void initView(AttributeSet attrs) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ThemeRefreshLayout);
        boolean isHeadLayout = false;
        if (typedArray != null) {
            isHeadLayout = typedArray.getBoolean(R.styleable.ThemeRefreshLayout_noHeadLoad, false);
        }
        if (isHeadLayout) {
            setRefreshHeader(new ClassicsHeader(getContext()).
                    setSpinnerStyle(SpinnerStyle.FixedBehind).
                    setPrimaryColorId(R.color.c_f6f6f6).
                    setAccentColorId(R.color.c_999999));
        } else {
            setRefreshHeader(new MaterialHeader(getContext()).
                    setColorSchemeColors(getResources().getColor(R.color.color_main)));
        }

        setRefreshFooter(new ClassicsFooter(getContext()).
                setSpinnerStyle(SpinnerStyle.FixedBehind).
                setPrimaryColorId(R.color.c_f6f6f6).
                setAccentColorId(R.color.c_999999));
    }
}
